function index(tbl){
	var pageNumber=1;
	if(tbl.pageNumber!=undefined){
		pageNumber=tbl.pageNumber
	}
	var cnd= Cnd.NEW();
	var agencys=$pager("agency",cnd,pageNumber,24)
	return agencys;
}
function apply(tbl){
	if(user()==null){
		return ">>:login?goto=agency/apply"
	}
	var agency=$fetch("agency",Cnd.where("status","=",0).and("user_id","=",user().id))
	attr("agency",agency)
}

function agency(tbl){
	var cnd=Cnd.NEW();
	if(tbl.id!=undefined){
		cnd.and("id","=",tbl.id)
	}else if(tbl.name!=undefined){
		cnd.and("name","=",tbl.name)
	}
	var agency=$fetch("agency",cnd);
	
	attr("count_course",$count("course","agency_id="+agency.id))
	attr("count_teacher",$count("teacher","agency_id="+agency.id))
	var list=$list("course",Cnd.where("agency_id","=",agency.id).desc("id"),1,6);
	list.forEach(function(c){
		c.put("teachers",$list("teacher",Cnd.where("name","in",Arrays.asList(c.teacher.split(",")))))
	})
	attr("courses",list)
	attr("teachers",$list("teacher","agency_id="+agency.id,1,4))
	return agency;
}

function course(tbl){
	var cnd=Cnd.NEW();
	if(tbl.id!=undefined){
		cnd.and("id","=",tbl.id)
	}else if(tbl.name!=undefined){
		cnd.and("name","=",tbl.name)
	}
	var agency=$fetch("agency",cnd);
	attr("count_course",$count("course","agency_id="+agency.id))
	attr("count_teacher",$count("teacher","agency_id="+agency.id))
	var list=$list("course",Cnd.where("agency_id","=",agency.id).desc("id"),1,10);
	list.forEach(function(c){
		c.put("teachers",$list("teacher",Cnd.where("name","in",Arrays.asList(c.teacher.split(",")))))
	})
	attr("courses",list)
	attr("teachers",$list("teacher","agency_id="+agency.id,1,4))
	attr("zbs",$list("zb","agency_id="+agency.id+" order by id desc",1,4))
	return agency;
}
function teacher(tbl){
	var cnd=Cnd.NEW();
	if(tbl.id!=undefined){
		cnd.and("id","=",tbl.id)
	}else if(tbl.name!=undefined){
		cnd.and("name","=",tbl.name)
	}
	var agency=$fetch("agency",cnd);
	attr("count_course",$count("course","agency_id="+agency.id))
	attr("count_teacher",$count("teacher","agency_id="+agency.id))
	var list=$list("course",Cnd.where("agency_id","=",agency.id).desc("id"),1,6);
	list.forEach(function(c){
		c.put("teachers",$list("teacher",Cnd.where("name","in",Arrays.asList(c.teacher.split(",")))))
	})
	attr("courses",list)
	attr("teachers",$list("teacher","agency_id="+agency.id,1,10))
	return agency;
}
function about(tbl){
	var cnd=Cnd.NEW();
	if(tbl.id!=undefined){
		cnd.and("id","=",tbl.id)
	}else if(tbl.name!=undefined){
		cnd.and("name","=",tbl.name)
	}
	var agency=$fetch("agency",cnd);
	attr("count_course",$count("course","agency_id="+agency.id))
	attr("count_teacher",$count("teacher","agency_id="+agency.id))
	var list=$list("course",Cnd.where("agency_id","=",agency.id).desc("id"),1,6);
	list.forEach(function(c){
		c.put("teachers",$list("teacher",Cnd.where("name","in",Arrays.asList(c.teacher.split(",")))))
	})
	attr("courses",list)
	attr("teachers",$list("teacher","agency_id="+agency.id,1,4))
	return agency;
}